package com.lxy.cloud.mqtt.client.service.impl;

import com.lxy.cloud.mqtt.client.constant.SystemConstant;
import com.lxy.cloud.mqtt.client.model.dto.BaseMqttDTO;
import com.lxy.cloud.mqtt.client.model.dto.LoginAccountInfoDTO;
import com.lxy.cloud.mqtt.client.model.dto.MqttGetDTO;
import com.lxy.cloud.mqtt.client.service.AbstractMessageProcessService;
import com.lxy.cloud.mqtt.client.util.MapUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: lxy
 * @Date: 2020/9/7 15:02
 * @Desc: 处理用户登录请求的get topic
 */
@Service(value = SystemConstant.USER_LOGIN)
public class UserLoginProcessServiceImpl extends AbstractMessageProcessService<MqttGetDTO<LoginAccountInfoDTO>> {
    @Override
    protected MqttGetDTO<LoginAccountInfoDTO> convertMessage(BaseMqttDTO request) {
        MqttGetDTO<LoginAccountInfoDTO> param = new MqttGetDTO<>();
        if (request instanceof MqttGetDTO) {
            BeanUtils.copyProperties(request, param);
            Object data = param.getData();
            if (data instanceof Map) {
                HashMap map = (HashMap) data;
                LoginAccountInfoDTO loginAccountInfo = MapUtil.mapToObject(map, LoginAccountInfoDTO.class);
                param.setData(loginAccountInfo);
            }
        }
        return param;
    }

    @Override
    protected void process(MqttGetDTO<LoginAccountInfoDTO> acpMessage) {
        System.out.println("acpMessage = " + acpMessage);
    }

}
